import json
from sdk.client import Client
from sdk.common import BuildClient

class DeviceState:
    def __init__(self, client):
        self.client = client

    def device_state_restart(self, req):
        self.app_id = self.client.app_id
        self.app_secret = self.client.app_secret
        post_params = BuildClient.build_post_param(self,req.__dict__) 
        return self.client.post("/open/device/state/restart", post_params)
    

    def device_state_offline(self, req):
        self.app_id = self.client.app_id
        self.app_secret = self.client.app_secret
        post_params = BuildClient.build_post_param(self,req.__dict__) 
        return self.client.post("/open/device/state/offline", post_params)

    def device_state_offline_profit(self, req):
        self.app_id = self.client.app_id
        self.app_secret = self.client.app_secret
        post_params = BuildClient.build_post_param(self,req.__dict__) 
        return self.client.post("/open/device/state/offline_profit", post_params)

    def device_state_port_error(self, req):
        self.app_id = self.client.app_id
        self.app_secret = self.client.app_secret
        post_params = BuildClient.build_post_param(self,req.__dict__) 
        return self.client.post("/open/device/state/port/error", post_params)

    def device_state(self, req):
        get_params = {
            "device_num": req.device_num,
            "port_fields": ','.join(req.port_fields) if req.port_fields else None
        }
        self.app_id = self.client.app_id
        self.app_secret = self.client.app_secret
        get_params = BuildClient.build_get_param(self,get_params)
        return self.client.get("/open/device/state", get_params)
    